package subject.tengxun.middle;

import java.util.*;

/**
 * 功能：
 * 作者：yedou
 * 日期：2025/3/13 23:37
 */
public class longestConsecutive {
    public static void main(String[] args) {
        int[] nums = {0, 3, 7, 2, 5, 8, 4, 6, 0, 1};
        HashSet<Integer> hashSet = new HashSet<>();
        // 将数字添加到集合当中
        for (int num : nums) {
            hashSet.add(num);
        }
        HashMap<Integer, Integer> hashMap = new HashMap<>();
        for (Integer item : hashSet) {
            int length = 0;
//            System.out.println(item);
            // 判断item是否为起点
            if (!hashSet.contains(item - 1)) {
                length = length + 1;
                // 判断 item作为起点有多少个连续的数字
                while (hashSet.contains(item + length)) {
                    length = length + 1;
                }
                hashMap.put(item, length);
            }
        }
        Set<Map.Entry<Integer, Integer>> entries = hashMap.entrySet();
        int max_value = 0;
        for (Map.Entry<Integer, Integer> entry : entries) {
            Integer value = entry.getValue();
            if (value > max_value) {
                max_value = value;
            }
        }
        System.out.println(max_value);
    }

}